package com.onLineCar.manages.pojo.dto;

import cn.hutool.core.bean.BeanUtil;
import com.onLineCar.common.security.utils.SecurityUtils;
import com.onLineCar.manages.pojo.CarModel;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;



import static com.onLineCar.manages.aspect.config.OperateLogAspect.userNameThreadLocal;


@Data
public class CarModelDTO {

    private Integer id;

    /**
     * 车辆品牌
     */
    @NotBlank(message = "车辆品牌不能为空")
    private String brand;

    /**
     * 车辆型号
     */
    @NotBlank(message = "车辆型号不能为空")
    private String model;

    /**
     * 车型描述
     */
    @NotBlank(message = "车型描述不能为空")
    private String description;

    /**
     * 车型图片
     */
    @NotBlank(message = "车型图片不能为空")
    private String image;

    /**
     * 车辆座位
     */
    @NotNull(message = "车辆座位不能为空")
    private Integer seats;

    /**
     * 状态
     */
    @NotBlank(message = "车辆状态不能为空")
    private String status;

    public CarModel convertCarModel(CarModelDTO carModelDTO, String username){
        CarModel carModel = new CarModel();
        BeanUtil.copyProperties(carModelDTO, carModel);
        if (StringUtils.isNoneBlank(username)) {
            carModel.setOperator(username);
        } else {

            carModel.setOperator(SecurityUtils.getUsername());

            carModel.setOperator(userNameThreadLocal.get());

        }
        return carModel;
    }
}
